

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/myblog/img/fluid.png">
  <link rel="icon" href="/myblog/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="ZTY">
  <meta name="keywords" content="">
  
    <meta name="description" content="小厂实习面试记录以及问题回顾~">
<meta property="og:type" content="article">
<meta property="og:title" content="小厂实习面试记录-003">
<meta property="og:url" content="https://zty-f.gitee.io/myblog/2022/05/12/%E5%B0%8F%E5%8E%82%E9%9D%A2%E8%AF%95%E8%AE%B0%E5%BD%95-003/index.html">
<meta property="og:site_name" content="zty-f">
<meta property="og:description" content="小厂实习面试记录以及问题回顾~">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://s3.bmp.ovh/imgs/2022/11/29/a8ab85ef94ffc80c.png">
<meta property="article:published_time" content="2022-05-12T10:29:35.000Z">
<meta property="article:modified_time" content="2024-12-28T02:09:42.875Z">
<meta property="article:author" content="ZTY">
<meta property="article:tag" content="记录">
<meta property="article:tag" content="实习">
<meta property="article:tag" content="大学">
<meta property="article:tag" content="面试">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://s3.bmp.ovh/imgs/2022/11/29/a8ab85ef94ffc80c.png">
  
  
    <meta name="referrer" content="no-referrer-when-downgrade">
  
  
  <title>小厂实习面试记录-003 - zty-f</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/myblog/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/myblog/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/myblog/css/highlight-dark.css" />
  



  
<link rel="stylesheet" href="//at.alicdn.com/t/c/font_3799348_11m20qbqwhmo.css">



  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"zty-f.gitee.io","root":"/myblog/","version":"1.9.3","typing":{"enable":true,"typeSpeed":150,"cursorChar":"_","loop":true,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/myblog/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/myblog/js/utils.js" ></script>
  <script  src="/myblog/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/myblog/">
      <strong>思前想后</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/myblog/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" target="_self" href="javascript:;" role="button"
                 data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <i class="iconfont icon-books"></i>
                魔盒
              </a>
              <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                
                  
                  
                  
                  <a class="dropdown-item" href="/myblog/archives/">
                    <i class="iconfont icon-archive-fill"></i>
                    归档
                  </a>
                
                  
                  
                  
                  <a class="dropdown-item" href="/myblog/categories/">
                    <i class="iconfont icon-yingyong"></i>
                    分类
                  </a>
                
                  
                  
                  
                  <a class="dropdown-item" href="/myblog/tags/">
                    <i class="iconfont icon-tags-fill"></i>
                    标签
                  </a>
                
              </div>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/myblog/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/myblog/links/">
                <i class="iconfont icon-link-fill"></i>
                友链
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" target="_blank" rel="noopener" href="https://github.com/zty-f">
                <i class="iconfont icon-GitHub"></i>
                
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/myblog/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="小厂实习面试记录-003"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        ZTY
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2022-05-12 18:29" pubdate>
          2022年5月12日 晚上
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          8.1k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          68 分钟
        
      </span>
    

    
    
      
        <span id="busuanzi_container_page_pv" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="busuanzi_value_page_pv"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">小厂实习面试记录-003</h1>
            
            
              <div class="markdown-body">
                
                <h3 id="1-单例模式创建方式"><a href="#1-单例模式创建方式" class="headerlink" title="1.单例模式创建方式"></a>1.单例模式创建方式</h3><p>1.饿汉式（静态常量）【可用】</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Singleton</span>&#123;<br> <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">static</span> Singleton INSTANCE=<span class="hljs-keyword">new</span> <span class="hljs-title class_">Singleton</span>();<br> <span class="hljs-keyword">private</span> <span class="hljs-title function_">Singleton</span><span class="hljs-params">()</span>&#123;&#125;<br> <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> Singleton <span class="hljs-title function_">getInstance</span><span class="hljs-params">()</span>&#123;<br>     <span class="hljs-keyword">return</span> INSTANCE;<br> &#125;<br> &#125;<br><br>优点：这种写法比较简单，就是在类装载的时候就完成实例化。避免了线程同步问题。<br>缺点：在类装载的时候就完成实例化，没有达到Lazy Loading的效果。如果从始至终从未使用过这个实例，则会造成内存的浪费。<br></code></pre></td></tr></table></figure>
<p>2.饿汉式（静态代码块）【可用】</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Singleton</span>&#123;<br>	<span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> Singleton instance;<br>    <span class="hljs-keyword">static</span>&#123;<br>         instance=<span class="hljs-keyword">new</span> <span class="hljs-title class_">Singleton</span>();<br>    &#125;<br>    <span class="hljs-keyword">private</span> <span class="hljs-title function_">Singleton</span><span class="hljs-params">()</span>&#123;&#125;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> Singleton <span class="hljs-title function_">getInstance</span><span class="hljs-params">()</span>&#123;<br>        <span class="hljs-keyword">return</span> instance;<br>    &#125;<br>&#125;<br>这种方式和上面的方式其实类似，只不过将类实例化的过程放在了静态代码块中，<br>也是在类装载的时候，就执行静态代码块中的代码，初始化类的实例。优缺点和上面是一样的。<br></code></pre></td></tr></table></figure>
<p>3.懒汉式（线程不安全）【不可用】</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> Singleton&#123;<br> 	<span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> Singletons singleton;<br> 	<span class="hljs-keyword">private</span> <span class="hljs-title function_">Singleton</span><span class="hljs-params">()</span>&#123;<br> 	<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> Singleton <span class="hljs-title function_">getInstance</span><span class="hljs-params">()</span>&#123;<br>     	<span class="hljs-keyword">if</span>(singleton==<span class="hljs-literal">null</span>)&#123;<br>     	    singleton=<span class="hljs-keyword">new</span> <span class="hljs-title class_">Singleton</span>();  <br>     	&#125;<br>     	<span class="hljs-keyword">return</span> singleton;<br>	 &#125;<br> &#125;<br> 这种写法起到了LazyLoading的效果，但是只能在单线程下使用。如果在多线程下，<br> 一个线程进入了<span class="hljs-keyword">if</span> (singleton ==<span class="hljs-literal">null</span>)判断语句块，还未来得及往下执行，<br> 另一个线程也通过了这个判断语句，这时便会产生多个实例。所以在多线程环境下不可使用这种方式。<br></code></pre></td></tr></table></figure>
<p>4.懒汉式（线程安全，同步方法）【不推荐用】</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Singleton</span>&#123;<br>     <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> Singleton singleton;<br>     <span class="hljs-keyword">private</span> <span class="hljs-title function_">Singleton</span><span class="hljs-params">()</span>&#123;&#125;<br>     <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">synchronized</span> Singleton <span class="hljs-title function_">getInstance</span><span class="hljs-params">()</span>&#123;<br>          <span class="hljs-keyword">if</span>(singleton==<span class="hljs-literal">null</span>)&#123;<br>             singleton=<span class="hljs-keyword">new</span> <span class="hljs-title class_">Singleton</span>();  <br>           &#125;<br>           <span class="hljs-keyword">return</span> singleton;<br>     &#125;<br>&#125;<br>解决上面第三种实现方式的线程不安全问题，做个线程同步就可以了，于是就对getInstance()方法进行了线程同步。<br>缺点：效率太低了，每个线程在想获得类的实例时候，执行getInstance()方法都要进行同步。<br>而其实这个方法只执行一次实例化代码就够了，后面的想获得该类实例，直接<span class="hljs-keyword">return</span>就行了。<br>方法进行同步效率太低要改进。<br></code></pre></td></tr></table></figure>

<p>5.懒汉式（线程安全，同步代码块）【不可用】</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Singleton</span>&#123;<br>     <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> Singleton singleton;<br>     <span class="hljs-keyword">private</span> <span class="hljs-title function_">Singleton</span><span class="hljs-params">()</span>&#123;&#125;<br>     <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span>  Singleton <span class="hljs-title function_">getInstance</span><span class="hljs-params">()</span>&#123;<br>          <span class="hljs-keyword">if</span>(singleton==<span class="hljs-literal">null</span>)&#123;<br>              <span class="hljs-keyword">synchronized</span> (Singleton.class)&#123;<br>                  singleton=<span class="hljs-keyword">new</span> <span class="hljs-title class_">Singleton</span>();  <br>              &#125;<br>           &#125;<br>           <span class="hljs-keyword">return</span> singleton;<br>     &#125;<br>&#125;<br>由于第四种实现方式同步效率太低，所以摒弃同步方法，改为同步产生实例化的的代码块。<br>但是这种同步并不能起到线程同步的作用。跟第<span class="hljs-number">3</span>种实现方式遇到的情形一致，假如一个线程<br>进入了<span class="hljs-keyword">if</span> (singleton ==<span class="hljs-literal">null</span>)判断语句块，还未来得及往下执行，另一个线程也通过了这个判断语句，<br>这时便会产生多个实例。<br></code></pre></td></tr></table></figure>

<p>6.双重检查【推荐使用】</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Singleton</span>&#123;<br>     <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">volatile</span> Singleton singleton;<br>     <span class="hljs-keyword">private</span> <span class="hljs-title function_">Singleton</span><span class="hljs-params">()</span>&#123;&#125;<br>     <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span>  Singleton <span class="hljs-title function_">getInstance</span><span class="hljs-params">()</span>&#123;<br>          <span class="hljs-keyword">if</span>(singleton==<span class="hljs-literal">null</span>)&#123;<br>              <span class="hljs-keyword">synchronized</span> (Singleton.class)&#123;<br>                     <span class="hljs-keyword">if</span>(singleton==<span class="hljs-literal">null</span>)&#123;<br>                          singleton=<span class="hljs-keyword">new</span> <span class="hljs-title class_">Singleton</span>();  <br>                      &#125;<br>              &#125;<br>           &#125;<br>           <span class="hljs-keyword">return</span> singleton;<br>     &#125;<br>&#125;<br>Double-Check概念对于多线程开发者来说不会陌生，如代码中所示，我们进行了两次<span class="hljs-keyword">if</span> (singleton ==<span class="hljs-literal">null</span>)检查，这样就可以保证线程安全了。这样，实例化代码只用执行一次，后面再次访问时，判断<span class="hljs-keyword">if</span>(singleton == <span class="hljs-literal">null</span>)，直接<span class="hljs-keyword">return</span>实例化对象。<br>优点：线程安全；延迟加载；效率较高。<br></code></pre></td></tr></table></figure>

<p>7.静态内部类【推荐使用】</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Singleton</span>&#123;<br>     <span class="hljs-keyword">private</span> <span class="hljs-title function_">Singleton</span><span class="hljs-params">()</span>&#123;&#125;<br>     <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">SingletonInstance</span>&#123;<br>            <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span>  <span class="hljs-keyword">final</span> Singleton INSTANCE=<span class="hljs-keyword">new</span> <span class="hljs-title class_">Singleton</span>();<br>     &#125;<br>     <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> Singleton <span class="hljs-title function_">getInstance</span><span class="hljs-params">()</span>&#123;<br>         <span class="hljs-keyword">return</span> SingletonInstance.INSTANCE;<br>     &#125;<br>&#125;<br>这种方式跟饿汉式方式采用的机制类似，但又有不同。两者都是采用了类装载的机制来保证初始化实例时只有一个线程。<br>不同的地方在饿汉式方式是只要Singleton类被装载就会实例化，没有Lazy-Loading的作用，而静态内部类方式在Singleton类被装载时并不会立即实例化，而是在需要实例化时，调用getInstance方法，才会装载SingletonInstance类，从而完成Singleton的实例化。<br><br>类的静态属性只会在第一次加载类的时候初始化，所以在这里，JVM帮助我们保证了线程的安全性，在类进行初始化时，别的线程是无法进入的。<br><br>优点：避免了线程不安全，延迟加载，效率高。<br></code></pre></td></tr></table></figure>

<p>8.枚举【推荐使用】</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">enum</span> <span class="hljs-title class_">Singleton</span>&#123;<br>       INSTANCE;<br>       <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> Singleton <span class="hljs-title function_">getInstance</span><span class="hljs-params">()</span>&#123;<br>           <span class="hljs-keyword">return</span> INSTANCE;<br>       &#125;<br>&#125;<br>借助JDK1<span class="hljs-number">.5</span>中添加的枚举来实现单例模式。不仅能避免多线程同步问题，而且还能防止反序列化重新创建新的对象。<br></code></pre></td></tr></table></figure>



<h3 id="2-集合概述"><a href="#2-集合概述" class="headerlink" title="2.集合概述"></a>2.集合概述</h3><p>Java集合类主要由两个接口<strong>Collection</strong>和<strong>Map</strong>派生出来的，Collection有三个子接口：List、Set、Queue。</p>
<p>Java集合框架图如下：</p>
<p><img src="https://s3.bmp.ovh/imgs/2022/05/12/7826b38c0b95257a.png" srcset="/myblog/img/loading.gif" lazyload></p>
<p><img src="https://s3.bmp.ovh/imgs/2022/05/12/510b34f190bdeeb6.png" srcset="/myblog/img/loading.gif" lazyload></p>
<p>List代表了有序可重复集合，可直接根据元素的索引来访问；</p>
<p>Set代表无序不可重复集合，只能根据元素本身来访问；</p>
<p>Queue是队列集合；</p>
<p>Map代表的是存储key-value对的集合，可根据元素的key来访问value。</p>
<p>集合体系中常用的实现类有<code>ArrayList、LinkedList、HashSet、TreeSet、HashMap、TreeMap</code>等实现类。</p>
<h3 id="3-线程创建方式"><a href="#3-线程创建方式" class="headerlink" title="3.线程创建方式"></a>3.线程创建方式</h3><ul>
<li>通过扩展<code>Thread</code>类来创建多线程</li>
<li>通过实现<code>Runnable</code>接口来创建多线程</li>
<li>实现<code>Callable</code>接口，通过<code>FutureTask</code>接口创建线程。</li>
<li>使用<code>Executor</code>框架来创建线程池。</li>
</ul>
<h3 id="4-异常概述"><a href="#4-异常概述" class="headerlink" title="4.异常概述"></a>4.异常概述</h3><h4 id="常见的Exception有哪些？"><a href="#常见的Exception有哪些？" class="headerlink" title="常见的Exception有哪些？"></a>常见的Exception有哪些？</h4><hr>
<p>常见的RuntimeException：</p>
<ol>
<li><code>ClassCastException</code> &#x2F;&#x2F;类型转换异常</li>
<li><code>IndexOutOfBoundsException</code> &#x2F;&#x2F;数组越界异常</li>
<li><code>NullPointerException</code> &#x2F;&#x2F;空指针</li>
<li><code>ArrayStoreException</code> &#x2F;&#x2F;数组存储异常</li>
<li><code>NumberFormatException</code> &#x2F;&#x2F;数字格式化异常</li>
<li><code>ArithmeticException</code> &#x2F;&#x2F;数学运算异常</li>
</ol>
<p>unchecked Exception：</p>
<ol>
<li><code>NoSuchFieldException</code> &#x2F;&#x2F;反射异常，没有对应的字段</li>
<li><code>ClassNotFoundException</code> &#x2F;&#x2F;类没有找到异常</li>
<li><code>IllegalAccessException</code> &#x2F;&#x2F;安全权限异常，可能是反射时调用了private方法</li>
</ol>
<h4 id="Error和Exception的区别？"><a href="#Error和Exception的区别？" class="headerlink" title="Error和Exception的区别？"></a>Error和Exception的区别？</h4><hr>
<p><strong>Error</strong>：JVM 无法解决的严重问题，如栈溢出<code>StackOverflowError</code>、内存溢出<code>OOM</code>等。程序无法处理的错误。</p>
<p><strong>Exception</strong>：其它因编程错误或偶然的外在因素导致的一般性问题。可以在代码中进行处理。如：空指针异常、数组下标越界等。</p>
<h4 id="运行时异常和非运行时异常（checked）的区别？"><a href="#运行时异常和非运行时异常（checked）的区别？" class="headerlink" title="运行时异常和非运行时异常（checked）的区别？"></a>运行时异常和非运行时异常（checked）的区别？</h4><hr>
<p><code>unchecked exception</code>包括<code>RuntimeException</code>和<code>Error</code>类，其他所有异常称为检查（checked）异常。</p>
<ol>
<li><code>RuntimeException</code>由程序错误导致，应该修正程序避免这类异常发生。</li>
<li><code>checked Exception</code>由具体的环境（读取的文件不存在或文件为空或sql异常）导致的异常。必须进行处理，不然编译不通过，可以catch或者throws。</li>
</ol>
<h3 id="5-SpringMVC的RequestMapping参数"><a href="#5-SpringMVC的RequestMapping参数" class="headerlink" title="5.SpringMVC的RequestMapping参数"></a>5.SpringMVC的RequestMapping参数</h3><ul>
<li><h4 id="value-代表实际的url"><a href="#value-代表实际的url" class="headerlink" title="value   代表实际的url"></a>value   代表实际的url</h4></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@Controller</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">HelloController</span>&#123;<br>        <span class="hljs-meta">@RequestMapping</span> (value = <span class="hljs-string">&quot;/hello&quot;</span>)<br>        <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">hello</span><span class="hljs-params">(HttpServletRequest request, HttpServletResponse response)</span> 				<span class="hljs-keyword">throws</span> IOException &#123;<br>            <br>        &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li><h4 id="param-指定某一种参数名类型，当请求数据中包含该名称的请求参数时，才能进行相应，否则拒绝此次请求。"><a href="#param-指定某一种参数名类型，当请求数据中包含该名称的请求参数时，才能进行相应，否则拒绝此次请求。" class="headerlink" title="param  指定某一种参数名类型，当请求数据中包含该名称的请求参数时，才能进行相应，否则拒绝此次请求。"></a>param  指定某一种参数名类型，当请求数据中包含该名称的请求参数时，才能进行相应，否则拒绝此次请求。</h4></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@RequestMapping(value = &quot;/findUser&quot;, param = &quot;username&quot;)</span><br></code></pre></td></tr></table></figure>

<ul>
<li><h4 id="method-请求方法，支持GET，POST，PUT，DELETE"><a href="#method-请求方法，支持GET，POST，PUT，DELETE" class="headerlink" title="method   请求方法，支持GET，POST，PUT，DELETE"></a>method   请求方法，支持GET，POST，PUT，DELETE</h4></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@RequestMapping</span> (value = <span class="hljs-string">&quot;/hello&quot;</span>, method = RequestMethod.GET)<br><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">hello</span> <span class="hljs-params">(HttpServletRequest request, HttpServletResponse response)</span> <span class="hljs-keyword">throws</span> 	IOException &#123;<br>         <br>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li><h4 id="consumes-接受的Content-Type类型"><a href="#consumes-接受的Content-Type类型" class="headerlink" title="consumes    接受的Content-Type类型"></a>consumes    接受的Content-Type类型</h4></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@RequestMapping</span> (value = <span class="hljs-string">&quot;/hello&quot;</span>, consumes = <span class="hljs-string">&quot;application/json&quot;</span>)<br><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">hello</span> <span class="hljs-params">(HttpServletRequest request, HttpServletResponse response)</span> <span class="hljs-keyword">throws</span> IOException &#123;<br>       <br>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li><h4 id="produces-返回的Content-Type"><a href="#produces-返回的Content-Type" class="headerlink" title="produces    返回的Content-Type"></a>produces    返回的Content-Type</h4></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@RequestMapping</span> (value = <span class="hljs-string">&quot;/hello&quot;</span>, produces = <span class="hljs-string">&quot;application/json&quot;</span>)<br><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">hello</span> <span class="hljs-params">(HttpServletRequest request, HttpServletResponse response)</span> <span class="hljs-keyword">throws</span> IOException &#123;<br>        <br>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li><h4 id="headers-用于指定某一种请求头类型。"><a href="#headers-用于指定某一种请求头类型。" class="headerlink" title="headers   用于指定某一种请求头类型。"></a>headers   用于指定某一种请求头类型。</h4></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@RequestMapping</span> (value = <span class="hljs-string">&quot;/hello&quot;</span>, headers = <span class="hljs-string">&quot;Content-Type:text/html;charset=UTF-8&quot;</span>)<br><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">hello</span> <span class="hljs-params">(HttpServletRequest request, HttpServletResponse response)</span> <span class="hljs-keyword">throws</span> IOException &#123;<br> <br>&#125;<br></code></pre></td></tr></table></figure>



<h3 id="6-Spring事务和隔离级别"><a href="#6-Spring事务和隔离级别" class="headerlink" title="6.Spring事务和隔离级别"></a>6.Spring事务和隔离级别</h3><h4 id="Spring-事务实现方式有哪些？"><a href="#Spring-事务实现方式有哪些？" class="headerlink" title="Spring 事务实现方式有哪些？"></a>Spring 事务实现方式有哪些？</h4><hr>
<p>事务就是一系列的操作原子执行。Spring事务机制主要包括声明式事务和编程式事务。</p>
<ul>
<li><strong>编程式事务</strong>：通过编程的方式管理事务，这种方式带来了很大的灵活性，但很难维护。</li>
<li><strong>声明式事务</strong>：将事务管理代码从业务方法中分离出来，通过aop进行封装。Spring声明式事务使得我们无需要去处理获得连接、关闭连接、事务提交和回滚等这些操作。使用 <code>@Transactional</code> 注解开启声明式事务。</li>
</ul>
<p><code>@Transactional</code>相关属性如下：</p>
<table>
<thead>
<tr>
<th>属性</th>
<th>类型</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>value</td>
<td>String</td>
<td>可选的限定描述符，指定使用的事务管理器</td>
</tr>
<tr>
<td>propagation</td>
<td>enum: Propagation</td>
<td>可选的事务传播行为设置</td>
</tr>
<tr>
<td>isolation</td>
<td>enum: Isolation</td>
<td>可选的事务隔离级别设置</td>
</tr>
<tr>
<td>readOnly</td>
<td>boolean</td>
<td>读写或只读事务，默认读写</td>
</tr>
<tr>
<td>timeout</td>
<td>int (in seconds granularity)</td>
<td>事务超时时间设置</td>
</tr>
<tr>
<td>rollbackFor</td>
<td>Class对象数组，必须继承自Throwable</td>
<td>导致事务回滚的异常类数组</td>
</tr>
<tr>
<td>rollbackForClassName</td>
<td>类名数组，必须继承自Throwable</td>
<td>导致事务回滚的异常类名字数组</td>
</tr>
<tr>
<td>noRollbackFor</td>
<td>Class对象数组，必须继承自Throwable</td>
<td>不会导致事务回滚的异常类数组</td>
</tr>
<tr>
<td>noRollbackForClassName</td>
<td>类名数组，必须继承自Throwable</td>
<td>不会导致事务回滚的异常类名字数组</td>
</tr>
</tbody></table>
<h4 id="有哪些事务传播行为？"><a href="#有哪些事务传播行为？" class="headerlink" title="有哪些事务传播行为？"></a>有哪些事务传播行为？</h4><hr>
<p>在TransactionDefinition接口中定义了七个事务传播行为：</p>
<ol>
<li><code>PROPAGATION_REQUIRED</code>如果存在一个事务，则支持当前事务。如果没有事务则开启一个新的事务。如果嵌套调用的两个方法都加了事务注解，并且运行在相同线程中，则这两个方法使用相同的事务中。如果运行在不同线程中，则会开启新的事务。</li>
<li><code>PROPAGATION_SUPPORTS</code> 如果存在一个事务，支持当前事务。如果没有事务，则非事务的执行。</li>
<li><code>PROPAGATION_MANDATORY</code> 如果已经存在一个事务，支持当前事务。如果不存在事务，则抛出异常<code>IllegalTransactionStateException</code>。</li>
<li><code>PROPAGATION_REQUIRES_NEW</code> 总是开启一个新的事务。需要使用JtaTransactionManager作为事务管理器。</li>
<li><code>PROPAGATION_NOT_SUPPORTED</code> 总是非事务地执行，并挂起任何存在的事务。需要使用JtaTransactionManager作为事务管理器。</li>
<li><code>PROPAGATION_NEVER</code> 总是非事务地执行，如果存在一个活动事务，则抛出异常。</li>
<li><code>PROPAGATION_NESTED</code> 如果一个活动的事务存在，则运行在一个嵌套的事务中。如果没有活动事务, 则按PROPAGATION_REQUIRED 属性执行。</li>
</ol>
<p><strong>PROPAGATION_NESTED 与PROPAGATION_REQUIRES_NEW的区别:</strong></p>
<p>使用<code>PROPAGATION_REQUIRES_NEW</code>时，内层事务与外层事务是两个独立的事务。一旦内层事务进行了提交后，外层事务不能对其进行回滚。两个事务互不影响。</p>
<p>使用<code>PROPAGATION_NESTED</code>时，外层事务的回滚可以引起内层事务的回滚。而内层事务的异常并不会导致外层事务的回滚，它是一个真正的嵌套事务。</p>
<h4 id="事务隔离级别"><a href="#事务隔离级别" class="headerlink" title="事务隔离级别"></a>事务隔离级别</h4><hr>
<table>
<thead>
<tr>
<th align="left"><strong>名称</strong></th>
<th><strong>结果</strong></th>
<th align="center">脏读</th>
<th align="center"><strong>不可重复读</strong></th>
<th align="center"><strong>幻读</strong></th>
</tr>
</thead>
<tbody><tr>
<td align="left">Read UnCommitted(读未提交)</td>
<td>什么都不解决</td>
<td align="center">√</td>
<td align="center">√</td>
<td align="center">√</td>
</tr>
<tr>
<td align="left">Read Committed(读已提交)</td>
<td>解决了脏读的问题</td>
<td align="center">–</td>
<td align="center">√</td>
<td align="center">√</td>
</tr>
<tr>
<td align="left">Repeatable Read(可重复读)</td>
<td>(mysql的默认级别)解决了不可重复读</td>
<td align="center">–</td>
<td align="center">–</td>
<td align="center">√</td>
</tr>
<tr>
<td align="left">Serializable(序列化)</td>
<td>解决所有问题</td>
<td align="center">-</td>
<td align="center">-</td>
<td align="center">-</td>
</tr>
</tbody></table>
<ul>
<li><p>READ UNCOMMITTED（读未提交数据）：允许事务读取未被其他事务提交的变更数据，会出现脏读、不可重复读和幻读问题。</p>
</li>
<li><p>READ COMMITTED（读已提交数据）：只允许事务读取已经被其他事务提交的变更数据，可避免脏读，仍会出现不可重复读和幻读问题。</p>
</li>
<li><p>REPEATABLE READ（可重复读）：确保事务可以多次从一个字段中读取相同的值，在此事务持续期间，禁止其他事务对此字段的更新，可以避免脏读和不可重复读，仍会出现幻读问题。</p>
</li>
<li><p>SERIALIZABLE（序列化）：确保事务可以从一个表中读取相同的行，在这个事务持续期间，禁止其他事务对该表执行插入、更新和删除操作，可避免所有并发问题，但性能非常低。</p>
<h4 id="Spring隔离级别"><a href="#Spring隔离级别" class="headerlink" title="Spring隔离级别"></a>Spring隔离级别</h4><hr>
</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-type">int</span> <span class="hljs-variable">ISOLATION_DEFAULT</span> <span class="hljs-operator">=</span> -<span class="hljs-number">1</span>;  <span class="hljs-comment">// 默认采用数据库的隔离级</span><br><span class="hljs-type">int</span> <span class="hljs-variable">ISOLATION_READ_UNCOMMITTED</span> <span class="hljs-operator">=</span> Connection.TRANSACTION_READ_UNCOMMITTED;<span class="hljs-comment">//读未提交</span><br><span class="hljs-type">int</span> <span class="hljs-variable">ISOLATION_READ_COMMITTED</span> <span class="hljs-operator">=</span> Connection.TRANSACTION_READ_COMMITTED; <span class="hljs-comment">//读已提交</span><br><span class="hljs-type">int</span> <span class="hljs-variable">ISOLATION_REPEATABLE_READ</span> <span class="hljs-operator">=</span> Connection.TRANSACTION_REPEATABLE_READ; <span class="hljs-comment">//可重复度</span><br><span class="hljs-type">int</span> <span class="hljs-variable">ISOLATION_SERIALIZABLE</span> <span class="hljs-operator">=</span> Connection.TRANSACTION_SERIALIZABLE;   <span class="hljs-comment">//序列化</span><br></code></pre></td></tr></table></figure>



<h3 id="7-强引用、软引用、弱引用、虚引用是什么，有什么区别？"><a href="#7-强引用、软引用、弱引用、虚引用是什么，有什么区别？" class="headerlink" title="7.强引用、软引用、弱引用、虚引用是什么，有什么区别？"></a>7.强引用、软引用、弱引用、虚引用是什么，有什么区别？</h3><p><strong>强引用</strong>：在程序中普遍存在的引用赋值，类似<code>Object obj = new Object()</code>这种引用关系。只要强引用关系还存在，垃圾收集器就永远不会回收掉被引用的对象。</p>
<p><strong>软引用</strong>：如果内存空间足够，垃圾回收器就不会回收它，如果内存空间不足了，就会回收这些对象的内存。</p>
<figure class="highlight haxe"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs haxe"><span class="hljs-comment">//软引用</span><br>SoftReference&lt;<span class="hljs-keyword">String</span>&gt; softRef = <span class="hljs-keyword">new</span> <span class="hljs-type">SoftReference</span>&lt;<span class="hljs-keyword">String</span>&gt;(str);<br></code></pre></td></tr></table></figure>

<p><strong>弱引用</strong>：在进行垃圾回收时，不管当前内存空间足够与否，都会回收只具有弱引用的对象。</p>
<figure class="highlight haxe"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs haxe"><span class="hljs-comment">//弱引用</span><br>WeakReference&lt;<span class="hljs-keyword">String</span>&gt; weakRef = <span class="hljs-keyword">new</span> <span class="hljs-type">WeakReference</span>&lt;<span class="hljs-keyword">String</span>&gt;(str);<br></code></pre></td></tr></table></figure>

<p><strong>虚引用</strong>：虚引用并不会决定对象的生命周期。如果一个对象仅持有虚引用，那么它就和没有任何引用一样，在任何时候都可能被垃圾回收。<strong>虚引用主要是为了能在对象被收集器回收时收到一个系统通知</strong>。</p>
<h3 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h3><ul>
<li>突然打来的电话面试，都不知道什么公司，虽然模模糊糊，也努力回答了，不知结果！</li>
<li>但是学习还是得继续！</li>
<li>加油！</li>
</ul>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/myblog/categories/%E9%9D%A2%E8%AF%95/" class="category-chain-item">面试</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/myblog/tags/%E8%AE%B0%E5%BD%95/">#记录</a>
      
        <a href="/myblog/tags/%E5%AE%9E%E4%B9%A0/">#实习</a>
      
        <a href="/myblog/tags/%E5%A4%A7%E5%AD%A6/">#大学</a>
      
        <a href="/myblog/tags/%E9%9D%A2%E8%AF%95/">#面试</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>小厂实习面试记录-003</div>
      <div>https://zty-f.gitee.io/myblog/2022/05/12/小厂面试记录-003/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>ZTY</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2022年5月12日</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>更新于</div>
          <div>2024年12月28日</div>
        </div>
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/myblog/2022/05/16/Golang%E5%AD%A6%E4%B9%A0-%E9%AB%98%E8%B4%A8%E9%87%8F%E7%BC%96%E7%A8%8B%E5%92%8C%E6%80%A7%E8%83%BD%E8%B0%83%E4%BC%98-%EF%BD%9C-%E9%9D%92%E8%AE%AD%E8%90%A5%E7%AC%94%E8%AE%B002/" title="Golang学习&amp;高质量编程和性能调优 ｜ 青训营笔记02">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Golang学习&amp;高质量编程和性能调优 ｜ 青训营笔记02</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/myblog/2022/05/08/Golang%E8%AF%AD%E8%A8%80%E5%88%9D%E5%AD%A6%E5%AD%A6%E4%B9%A0%E8%AE%B0%E5%BD%95%E5%92%8C%E6%80%BB%E7%BB%93-%EF%BD%9C-%E9%9D%92%E8%AE%AD%E8%90%A5%E7%AC%94%E8%AE%B001/" title="Golang语言初学学习记录和总结 ｜ 青训营笔记01">
                        <span class="hidden-mobile">Golang语言初学学习记录和总结 ｜ 青训营笔记01</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  <article id="comments" lazyload>
    
  <div id="valine"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#valine', function() {
      Fluid.utils.createScript('https://lib.baomitu.com/valine/1.5.1/Valine.min.js', function() {
        var options = Object.assign(
          {"appId":"wLiqWYFHh2NEnXVcULmB4KWQ-gzGzoHsz","appKey":"GSfJMcM0GcCzp1HDNXJfd9Bt","path":"window.location.pathname","placeholder":"欢迎大家积极评论~  支持Markdown格式~","avatar":"wavatar","meta":["nick","mail","link"],"requiredFields":["nick","mail"],"pageSize":10,"lang":"zh-CN","highlight":true,"recordIP":true,"serverURLs":"https://wliqwyfh.lc-cn-n1-shared.com","emojiCDN":null,"emojiMaps":null,"enableQQ":true},
          {
            el: "#valine",
            path: window.location.pathname
          }
        )
        new Valine(options);
        Fluid.utils.waitElementVisible('#valine .vcontent', () => {
          var imgSelector = '#valine .vcontent img:not(.vemoji)';
          Fluid.plugins.imageCaption(imgSelector);
          Fluid.plugins.fancyBox(imgSelector);
        })
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


  </article>


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
      <div class="col-lg-7 mx-auto nopadding-x-md">
        <div class="container custom mx-auto">
          <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css"> <script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/meting@2.0.1/dist/Meting.min.js"></script> <meting-js server="netease"  type="playlist"  id="7708362143" fixed="true"  mini="true" order="list" loop="all" preload="auto" list-folded="true" autoplay="true" theme="red"> </meting-js>
        </div>
      </div>
    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://github.com/zty-f" target="_blank" rel="nofollow noopener"><span>Copyright &copy;</span></a> <a href="http://www.zty-f.fun/" target="_blank" rel="nofollow noopener"><span>zty-f</span></a> 
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="busuanzi_container_site_pv" style="display: none">
        总访问量 
        <span id="busuanzi_value_site_pv"></span>
         次
      </span>
    
    
      <span id="busuanzi_container_site_uv" style="display: none">
        总访客数 
        <span id="busuanzi_value_site_uv"></span>
         人
      </span>
    
    
  
</div>

  
  
    <!-- 备案信息 ICP for China -->
    <div class="beian">
  <span>
    <a href="http://beian.miit.gov.cn/" target="_blank" rel="nofollow noopener">
      蜀ICP备2022002077号-1
    </a>
  </span>
  
</div>

  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/myblog/js/events.js" ></script>
<script  src="/myblog/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/myblog/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/myblog/js/local-search.js" ></script>

  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/myblog/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
